package test;

// 1. 封装
class Student {
    private String name;
    private int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name != null) this.name = name;
    }
}

// 2. 继承
class Animal {
    public void eat() {
        System.out.println("Animal eats");
    }
}

class Dog extends Animal {
    @Override
    public void eat() {
        System.out.println("Dog eats bones");
    }
}

// 3. 多态
class Cat extends Animal {
    @Override
    public void eat() {
        System.out.println("Cat eats fish");
    }
}

// 4. 抽象类
abstract class Shape {
    abstract void draw();

    void rotate() {
        System.out.println("Rotating");
    }
}

// 5. 接口
interface Swimmable {
    void swim();

    default void dive() {
        System.out.println("Diving");
    }
}

// 6. 静态属性/方法
class MathUtils {
    static final double PI = 3.14;

    static int add(int a, int b) {
        return a + b;
    }
}

// 7. final关键字
final class Immutable {
    final int value = 100;
}

// 8. 枚举
enum Status {ON, OFF}

// 9. 内部类
class Outer {
    class Inner {
        void show() {
            System.out.println("Inner");
        }
    }
}

// 测试类
public class A {
    public static void main(String[] args) {
        // 测试多态
        Animal animal1 = new Dog();
        Animal animal2 = new Cat();
        animal1.eat();
        animal2.eat();

        // 测试静态方法
        System.out.println(MathUtils.add(2, 3));

        // 测试内部类
        Outer outer = new Outer();
        Outer.Inner inner = outer.new Inner();
        inner.show();
    }
}